<?php

declare(strict_types=1);

use App\Orchid\Screens\Examples\ExampleActionsScreen;
use App\Orchid\Screens\Examples\ExampleCardsScreen;
use App\Orchid\Screens\Examples\ExampleChartsScreen;
use App\Orchid\Screens\Examples\ExampleFieldsAdvancedScreen;
use App\Orchid\Screens\Examples\ExampleFieldsScreen;
use App\Orchid\Screens\Examples\ExampleGridScreen;
use App\Orchid\Screens\Examples\ExampleLayoutsScreen;
use App\Orchid\Screens\Examples\ExampleScreen;
use App\Orchid\Screens\Examples\ExampleTextEditorsScreen;
use App\Orchid\Screens\PlatformScreen;
use App\Orchid\Screens\Post\PostEditScreen;
use App\Orchid\Screens\Post\PostListScreen;
use App\Orchid\Screens\Category\CategoryEditScreen;
use App\Orchid\Screens\Category\CategoryListScreen;
use App\Orchid\Screens\Tag\TagEditScreen;
use App\Orchid\Screens\Tag\TagListScreen;
use App\Orchid\Screens\Page\PageEditScreen;
use App\Orchid\Screens\Page\PageListScreen;
use App\Orchid\Screens\Setting\SettingEditScreen;
use App\Orchid\Screens\Setting\SettingListScreen;
use App\Orchid\Screens\Role\RoleEditScreen;
use App\Orchid\Screens\Role\RoleListScreen;
use App\Orchid\Screens\User\UserEditScreen;
use App\Orchid\Screens\User\UserListScreen;
use App\Orchid\Screens\User\UserProfileScreen;
use App\Orchid\Screens\Media\MediaListScreen;
use Illuminate\Support\Facades\Route;
use Tabuna\Breadcrumbs\Trail;

/*
|--------------------------------------------------------------------------
| Dashboard Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the need "dashboard" middleware group. Now create something great!
|
*/

// Main
Route::screen('/main', PlatformScreen::class)
    ->name('platform.main');

// 添加根路由重定向
Route::redirect('/admin', '/admin/main');

// Platform > Profile
Route::screen('profile', UserProfileScreen::class)
    ->name('platform.profile')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push(__('Profile'), route('platform.profile')));

// Platform > System > Users > User
Route::screen('users/{user}/edit', UserEditScreen::class)
    ->name('platform.systems.users.edit')
    ->middleware('platform.permission:platform.systems.users')
    ->breadcrumbs(fn (Trail $trail, $user) => $trail
        ->parent('platform.systems.users')
        ->push($user->name, route('platform.systems.users.edit', $user)));

// Platform > System > Users > Create
Route::screen('users/create', UserEditScreen::class)
    ->name('platform.systems.users.create')
    ->middleware('platform.permission:platform.systems.users')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.systems.users')
        ->push(__('Create'), route('platform.systems.users.create')));

// Platform > System > Users
Route::screen('users', UserListScreen::class)
    ->name('platform.systems.users')
    ->middleware('platform.permission:platform.systems.users')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push(__('Users'), route('platform.systems.users')));

// Platform > System > Roles > Role
Route::screen('roles/{role}/edit', RoleEditScreen::class)
    ->name('platform.systems.roles.edit')
    ->middleware('platform.permission:platform.systems.roles')
    ->breadcrumbs(fn (Trail $trail, $role) => $trail
        ->parent('platform.systems.roles')
        ->push($role->name, route('platform.systems.roles.edit', $role)));

// Platform > System > Roles > Create
Route::screen('roles/create', RoleEditScreen::class)
    ->name('platform.systems.roles.create')
    ->middleware('platform.permission:platform.systems.roles')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.systems.roles')
        ->push(__('Create'), route('platform.systems.roles.create')));

// Platform > System > Roles
Route::screen('roles', RoleListScreen::class)
    ->name('platform.systems.roles')
    ->middleware('platform.permission:platform.systems.roles')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push(__('Roles'), route('platform.systems.roles')));

// Example...
Route::screen('example', ExampleScreen::class)
    ->name('platform.example')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('Example Screen'));

Route::screen('/examples/form/fields', ExampleFieldsScreen::class)->name('platform.example.fields');
Route::screen('/examples/form/advanced', ExampleFieldsAdvancedScreen::class)->name('platform.example.advanced');
Route::screen('/examples/form/editors', ExampleTextEditorsScreen::class)->name('platform.example.editors');
Route::screen('/examples/form/actions', ExampleActionsScreen::class)->name('platform.example.actions');

Route::screen('/examples/layouts', ExampleLayoutsScreen::class)->name('platform.example.layouts');
Route::screen('/examples/grid', ExampleGridScreen::class)->name('platform.example.grid');
Route::screen('/examples/charts', ExampleChartsScreen::class)->name('platform.example.charts');
Route::screen('/examples/cards', ExampleCardsScreen::class)->name('platform.example.cards');

// Route::screen('idea', Idea::class, 'platform.screens.idea');

// 文章管理
Route::screen('posts', PostListScreen::class)
    ->name('platform.posts')
    ->middleware('platform.permission:platform.posts.list')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('文章管理', route('platform.posts')));
    
Route::screen('posts/create', PostEditScreen::class)
    ->name('platform.posts.create')
    ->middleware('platform.permission:platform.posts.create')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.posts')
        ->push('创建文章', route('platform.posts.create')));
    
Route::screen('posts/{post}/edit', PostEditScreen::class)
    ->name('platform.posts.edit')
    ->middleware('platform.permission:platform.posts.edit')
    ->breadcrumbs(fn (Trail $trail, $post) => $trail
        ->parent('platform.posts')
        ->push('编辑文章', route('platform.posts.edit', $post)));

// 分类管理
Route::screen('categories', CategoryListScreen::class)
    ->name('platform.categories')
    ->middleware('platform.permission:platform.categories')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('分类管理', route('platform.categories')));
    
Route::screen('categories/create', CategoryEditScreen::class)
    ->name('platform.categories.create')
    ->middleware('platform.permission:platform.categories')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.categories')
        ->push('创建分类', route('platform.categories.create')));
    
Route::screen('categories/{category}/edit', CategoryEditScreen::class)
    ->name('platform.categories.edit')
    ->middleware('platform.permission:platform.categories')
    ->breadcrumbs(fn (Trail $trail, $category) => $trail
        ->parent('platform.categories')
        ->push('编辑分类', route('platform.categories.edit', $category)));

// 标签管理
Route::screen('tags', TagListScreen::class)
    ->name('platform.tags')
    ->middleware('platform.permission:platform.tags')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('标签管理', route('platform.tags')));
    
Route::screen('tags/create', TagEditScreen::class)
    ->name('platform.tags.create')
    ->middleware('platform.permission:platform.tags')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.tags')
        ->push('创建标签', route('platform.tags.create')));
    
Route::screen('tags/{tag}/edit', TagEditScreen::class)
    ->name('platform.tags.edit')
    ->middleware('platform.permission:platform.tags')
    ->breadcrumbs(fn (Trail $trail, $tag) => $trail
        ->parent('platform.tags')
        ->push('编辑标签', route('platform.tags.edit', $tag)));

// 页面管理
Route::screen('pages', PageListScreen::class)
    ->name('platform.pages')
    ->middleware('platform.permission:platform.pages.list')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('页面管理', route('platform.pages')));
    
Route::screen('pages/create', PageEditScreen::class)
    ->name('platform.pages.create')
    ->middleware('platform.permission:platform.pages.create')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.pages')
        ->push('创建页面', route('platform.pages.create')));
    
Route::screen('pages/{page}/edit', PageEditScreen::class)
    ->name('platform.pages.edit')
    ->middleware('platform.permission:platform.pages.edit')
    ->breadcrumbs(fn (Trail $trail, $page) => $trail
        ->parent('platform.pages')
        ->push('编辑页面', route('platform.pages.edit', $page)));

// 媒体库管理
Route::screen('media', MediaListScreen::class)
    ->name('platform.media')
    ->middleware('platform.permission:platform.media')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('媒体库', route('platform.media')));

// 系统设置
Route::screen('settings', SettingListScreen::class)
    ->name('platform.settings')
    ->middleware('platform.permission:platform.settings')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.index')
        ->push('系统设置', route('platform.settings')));
    
Route::screen('settings/create', SettingEditScreen::class)
    ->name('platform.settings.create')
    ->middleware('platform.permission:platform.settings')
    ->breadcrumbs(fn (Trail $trail) => $trail
        ->parent('platform.settings')
        ->push('创建设置', route('platform.settings.create')));
    
Route::screen('settings/{setting}/edit', SettingEditScreen::class)
    ->name('platform.settings.edit')
    ->middleware('platform.permission:platform.settings')
    ->breadcrumbs(fn (Trail $trail, $setting) => $trail
        ->parent('platform.settings')
        ->push('编辑设置', route('platform.settings.edit', $setting)));
